const Router = require('koa-router')()
const mongoose = require('mongoose')

Router.post('/', async (ctx) => {
  const pwd = ctx.request.body.pwd
  const phone = ctx.session.phone
  const table = mongoose.model('bee')
  try {
    const body = await table.findOne({ phone })
    if (pwd == body.paypwd) {
      ctx.body = {
        code: 200,
        msg: '购买成功',
        pwd
      }
    } else {
      ctx.body = {
        code: 401,
        msg: '密码错误'
      }
    }
  } catch (err) {
    ctx.body = {
      code: 400,
      msg: '错误'
    }
  }
})

module.exports = Router
